{% extends 'base.html' %}

{% block content %}
    <div class="media">
        <a href="{{ url_for('auth.profile') }}">
            <img src="{{ url_for('static', filename='avatars/' + post.user.avatar) }}" class="rounded-circle" width="80"
                 height="80" alt="头像">
        </a>
        <div class="media-body">
            <h1 class="mt-0">{{ post.title }}</h1>
            <span class="text-muted">作者: <a class="text-sm" href="{{ url_for('auth.user_posts', username=post.user.username) }}">{{ post.user.username }}</a>
               创建于 {{ post.created.strftime('%Y-%m-%d %H:%M') }}
        </span>
            {% if post.user == current_user %}
                <a class="btn btn-outline-secondary" href="{{ url_for('post.update_post', post_id=post.id) }}">编辑</a>
                <button class="btn btn-outline-danger" data-toggle="modal" data-target="#deleteModal">删除</button>
            {% endif %}

            <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
                 aria-hidden="true">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="deleteModalLabel">删除文章</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                            <form method="POST" action="{{ url_for('post.delete_post', post_id=post.id) }}">
                                <input type="submit" class="btn btn-danger" value="删除">
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <p>{{ post.content }}</p>
        </div>
    </div>
{% endblock %}
